Skip to content

Conversation

@steinybot
Copy link
Collaborator

If trying to run sbt in a git worktree with the sbt-git plugin then it fails with:

jason@goodness> sbt                                                                                                                                             ~/src/kyo2
[info] welcome to sbt 1.10.0 (Oracle Corporation Java 21.0.2)
[info] loading settings for project global-plugins from plugins.sbt ...
    "-encoding",
[info] loading global plugins from /Users/jason/.sbt/1.0/plugins
[info] loading settings for project kyo2-build from plugins.sbt ...
[info] loading project definition from /Users/jason/src/kyo2/project
[info] loading settings for project kyo2 from build.sbt ...
[info] resolving key references (24619 settings) ...
org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index
	at org.eclipse.jgit.lib.Repository.getWorkTree(Repository.java:1570)
	at org.eclipse.jgit.treewalk.FileTreeIterator.<init>(FileTreeIterator.java:87)
	at org.eclipse.jgit.treewalk.FileTreeIterator.<init>(FileTreeIterator.java:73)
	at org.eclipse.jgit.api.StatusCommand.call(StatusCommand.java:113)
	at com.github.sbt.git.JGit.hasUncommittedChanges(JGit.scala:94)
	at com.github.sbt.git.SbtGit$.$anonfun$buildSettings$22(GitPlugin.scala:126)
	at com.github.sbt.git.SbtGit$.$anonfun$buildSettings$22$adapted(GitPlugin.scala:126)
	at com.github.sbt.git.DefaultReadableGit.withGit(ReadableGit.scala:44)
    "-encoding",
	at com.github.sbt.git.SbtGit$.$anonfun$buildSettings$21(GitPlugin.scala:126)
	at com.github.sbt.git.SbtGit$.$anonfun$buildSettings$21$adapted(GitPlugin.scala:126)
	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
	at sbt.internal.util.EvaluateSettings$MixedNode.evaluate0(INode.scala:229)
	at sbt.internal.util.EvaluateSettings$INode.evaluate(INode.scala:171)
	at sbt.internal.util.EvaluateSettings.$anonfun$submitEvaluate$1(INode.scala:88)
	at sbt.internal.util.EvaluateSettings.sbt$internal$util$EvaluateSettings$$run0(INode.scala:100)
	at sbt.internal.util.EvaluateSettings$$anon$3.run(INode.scala:95)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1583)
[error] org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index
[error] Use 'last' for the full log.
[warn] Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? (default: r)

This fixes that.

See sbt/sbt-git#110.

@steinybot steinybot force-pushed the git-worktree-support branch from e56de74 to 3754714 Compare June 2, 2024 11:05
val zioVersion = "2.1.1"
val scalaTestVersion = "3.2.18"

val isCI = Try(sys.env.getOrElse("CI", "false").toBoolean).getOrElse(false)
Copy link
Collaborator

@fwbrasil fwbrasil Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this flag be specific to the workaround instead of CI? Should the workaround be disabled in CI?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Having a separate environment variable would work for me as I use direnv so I could have a .envrc file in my worktree that enables the workaround. That being said, it would be hard to discover. I might be able to wrap the command that causes the error to provide the workaround information to users. Ideally the plugin would do this itself. Might be worth submitting a PR for that.

As for it being disabled in CI, yeah, I don't think there is any reason to change the default behaviour in CI as CI never uses worktrees.

@steinybot
Copy link
Collaborator Author

Closing this in favour of #483.

@steinybot steinybot closed this Jun 12, 2024
@steinybot steinybot deleted the git-worktree-support branch June 12, 2024 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants